package com.yzt.zhuju.dialog;

import android.content.DialogInterface;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.yzt.zhuju.R;
import com.yzt.zhuju.constants.IntentConstant;

/**
 * author : bob
 * date   : 2022/11/30
 * desc   :
 */
 public class MessageTipDialog extends BaseDialog {

    private String content;

    private String title;

    private String btnContent;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(STYLE_NO_TITLE, R.style.DialogCenterCustomeStyle);
    }

    @Override
    public void onStart() {
        super.onStart();
        getDialog().setCancelable(false);
        getDialog().setCanceledOnTouchOutside(false);
    }

    @Override
    public int getGravity() {
        return Gravity.CENTER;
    }

    @Override
    public int getLayoutRes() {
        return R.layout.dialog_message_hint_tip;
    }

    @Override
    public void bindView(View v) {
        if (getArguments() == null) {
            return;
        }
        content = getArguments().getString(IntentConstant.INTENT_CONTENT);
        title = getArguments().getString(IntentConstant.INTENT_TITLE);
        btnContent = getArguments().getString(IntentConstant.INTENT_SUBMIT);
        getDialog().setOnKeyListener(new DialogInterface.OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                return keyCode == KeyEvent.KEYCODE_BACK;
            }
        });
        initView(v);
    }

    /**
     * 初始化信息
     */
    private void initView(View view) {
        TextView mContentTv1 = view.findViewById(R.id.content_tv1);
        if(!TextUtils.isEmpty(content)) {
            mContentTv1.setText(content);
        }
        TextView titleTv = view.findViewById(R.id.title_tv);
        if (!TextUtils.isEmpty(title)) {
            titleTv.setText(title);
        }
        Button mSubmitBtn = view.findViewById(R.id.submit_tv);
        if (!TextUtils.isEmpty(btnContent)) {
            mSubmitBtn.setText(btnContent);
        }
        mSubmitBtn.setOnClickListener(v -> {
            dismissAllowingStateLoss();
            if (listener != null) {
                listener.submitClick();
            }
        });
    }

    private OnClickLoginDialogListener listener;

    public void setOnClickLoginDialogListener(OnClickLoginDialogListener listener) {
        this.listener = listener;
    }

    public interface OnClickLoginDialogListener {

        void submitClick();
    }
}
